//import { Util } from './../framework/util';
//import { GameManager } from './gameManager';
import { _decorator, Component, Node, Vec3, Quat, ParticleSystemComponent, math, ITriggerEvent, BoxColliderComponent, Prefab, CCFloat, CCBoolean, Game } from 'cc';
import { poolManager } from '../../../Framework/Scripts/Managers/poolManager';
import { ResMgr } from '../../../Framework/Scripts/Managers/ResMgr';
import { CocosUtils } from '../../../Framework/Scripts/Utils/CocosUtils';
import myUtil from '../../../Framework/Scripts/Utils/myUtil';
import { constant } from '../constant';
import { GameApp } from '../GameApp';
import { enemyBase } from './enemyBase';
import MapNavAgent from './MapNavAgent';




/** 
  周无邪出品
  本源码用于学习研究使用。
  作者联系方式：tuya7078（微信）。
 */

const { ccclass, property } = _decorator;
@ccclass('bulletGun')
export class bulletGun extends Component {
    @property({ type: CCFloat, displayName: "伤害" })
    private hitNum: number = 5;


    //private hitName: string = ""
    private howHit: Node = null



    public isAutoRotate: boolean = true;//箭是否自动调整角度
    public isArrowLaunch: boolean = false;//箭是否弹射


    private nav: MapNavAgent = null
    // private _releaseWorPos: Vec3 = new Vec3();//技能释放位置的世界坐标







    onLoad() {

        this.nav = this.node.getComponent(MapNavAgent)
        this.hitNum += GameApp.Instance.level * this.hitNum * constant.towerAttack
    }



    /**
    * 初始化 
    */
    public init(howHit: Node, targetNode: Node, speed: number, dir: Vec3, releaseWorPos: Vec3, disappearRange: number) {





        this.howHit = howHit
     //   this.hitName = GameApp.Instance.hitName


        this.node.setWorldPosition(releaseWorPos)
        this.node.forward = dir



        if (this.nav) {
            this.nav.InitMapNavAgent(speed)
            console.log("速度：", speed);

            this.nav.NavOnRoad([targetNode.getWorldPosition()], () => {
                //击中效果 
                //敌人掉血
                const ts: enemyBase = targetNode.getComponent(enemyBase)
                if (ts) {


                    ts.hit(this.hitNum, this.howHit)
                }
                // GameApp.Instance.playerTs.hit(20,this.node)
                poolManager.instance.putNode(this.node)
            })

        }
    }











}